package com.ocom.company.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.company.EntityComDockApi;
import com.ocom.common.entity.company.EntityCompanyDock;
import com.ocom.common.vo.company.CompanyDockComListVo;
import com.ocom.common.vo.company.CompanyDockListVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoCompanyDock extends BaseMapper<EntityCompanyDock> {

    @Select({"<script>",
            "select " +
                    "c.dock_code AS dockCode, " +
                    "c.server_code AS serverCode, " +
                    "c.remark, " +
                    "c.com_appid AS comAppid, " +
                    "d.dock_name AS dockName, " +
                    "s.server_name AS serverName  " +
                    "FROM company_dock c " +
                    "LEFT JOIN dock_list d ON d.dock_code = c.dock_code  " +
                    "LEFT JOIN dock_server s ON s.dock_code = d.dock_code AND s.server_code = c.server_code " +
                    "where c.com_id = #{comId}  " +
                    "</script>"})
    List<CompanyDockListVo> getComDockList(@Param("comId") Long comId);

    @Select({"<script>",
            "SELECT " +
                    " c.com_id AS comId, " +
                    " c.server_code AS serverCode, " +
                    " c.remark, " +
                    " c.com_appid AS comAppid, " +
                    " i.com_name AS comName, " +
                    " s.server_name AS serverName " +
                    " FROM " +
                    " (company_dock c, company_list i) " +
                    " LEFT JOIN dock_server s ON s.dock_code = c.dock_code " +
                    " AND s.server_code = c.server_code " +
                    " WHERE " +
                    " c.dock_code = #{dockCode} " +
                    " AND i.com_id = c.com_id " +
                    " <when test=\"serverCode!=null  \" > "+
                    " AND c.server_code = #{serverCode} " +
                    " </when> "+
                    " ORDER BY " +
                    " c.com_id" +
                    "</script>"})
    List<CompanyDockComListVo> getDockComList(@Param("dockCode") String dockCode, @Param("serverCode") String serverCode);
}
